<?php

namespace Modules\Admin\Http\Controllers;

use Illuminate\Support\Facades\Request;
use Modules\Admin\Service\CouponService;
use Modules\Admin\Http\Requests\Coupon\CouponRequest;

class CouponController extends BaseController
{   
    private $coupon_types = ['1'=>'洗车券','2'=>'满减券','3'=>'折扣券'];

	/**
     *  优惠券列表
     *  hinq 2019 08 21
     *
     **/
    public function index(){
        $arr_search = (array) Request::input();
        $arr_list = CouponService::get_list( (array) $arr_search );
        return view('admin::coupon.index',$arr_list['data']);
    }


    /**
     *	添加优惠券视图
     *	hinq 2019 08 22
     *
     **/
    public function create(){
      return view('admin::coupon.create' , ['coupons_types'=>$this->coupon_types]);
    }


    /**
     *	添加优惠券数据
     *	hinq 2019 08 22
     *
     **/
    public function store(){
    	$arrInput = (array) Request::all();
    	return CouponService::add_one( (array) $arrInput );

    }


    /**
     *	编辑优惠券视图
     *	hinq 2019 08 22 
     *
     **/
    public function edit(){
    	$nId = (int) Request::get('id',0);
    	$arr_info = CouponService::get_one( (int) $nId );
        return view('admin::coupon.edit',['info' => $arr_info ,'coupons_types'=>$this->coupon_types]);
    }


    /**
     *	编辑优惠券数据
     *	hinq 2019 08 22
     *
     **/
    public function update(){
    	$arrInput = (array) Request::all();
    	return CouponService::edit_one( (array) $arrInput );
    }


    /**
     *  优惠券使用、领取明细列表
     *  hinq 2019 08 29
     *
     **/
    public function list(){
        $arr_search = (array) Request::all();
        $arr_list = CouponService::get_list_to_use( (array) $arr_search );
        echo_error($arr_list);
        return view('admin::coupon.list',$arr_list['data']);
    }


    /**
     *  使用优惠券 搜索优惠券券号使用
     *  hinq  2019 09 06
     *
     **/
    public function coupon_use(){
        $nId = (int) Request::get('id');
        return CouponService::coupon_use( (int) $nId );
    }


    /**
     *  优惠券关联用户详情
     *  hinq 2019 09 17
     *
     **/
    public function list_extend(){
        $arr_search = (array) Request::all();
        $arr_list = CouponService::list_extend( (array) $arr_search );
        echo_error($arr_list);
        return view('admin::coupon.list_extend',$arr_list['data']);
    }
}
